#ifndef DRAGSPINBOX_H
#define DRAGSPINBOX_H

#include <QSpinBox>

class DragSpinBox : public QSpinBox
{
    Q_OBJECT
public:
    explicit DragSpinBox(QWidget *parent = 0);
    void SetRangeLength(int length);
    void SetCanDragSetValue(bool dragSetValue);
    bool CanDragSetValue(void)const { return m_canDragSetVaule; }
    void setRange(int minimum, int maximum);  //重定义

protected:
    virtual void enterEvent(QEvent *event) Q_DECL_OVERRIDE;
    virtual void leaveEvent(QEvent *event) Q_DECL_OVERRIDE;
    virtual bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;

private:
    void SolveScale(void);
    void SolveLeftRightLength(void);
private:
    bool m_isDragging;
    QPoint m_pressedPoint;
    int m_pressedValue;

    int m_rangeLength;
    bool m_canDragSetVaule;

    double m_scale;     //比例关系为  value / px
    int m_leftLength;
    int m_rightLength;
};

#endif // DRAGSPINBOX_H
